package com.example.myapplication.kotlin

/**
 * @author: rongfeng
 * @date: 2022/1/14
 * @description
 */
class Generic {

    interface Food {
        fun getName()
    }

    class Apple : Food {
        override fun getName() {
            println("apple")
        }
    }

    class Banana : Food {
        override fun getName() {
            println("banana")
        }
    }

    interface Box<T> {
        fun set(t: T)
        fun getOut(): T
    }

    //传进的对象无法再返回了
    interface BoxIn<in T> {
        fun set(t: T)
    }

    //无法传入此类型对象
    interface BoxOut<out T> {
        fun get(): T
    }


    fun buy(boxFood: Box<Food>) {
        boxFood.set(Apple())
        boxFood.getOut().getName()
    }

    fun buyIn(boxFood: Box<in Apple>) {

    }


    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val generic = Generic()
//            generic.buy(object : Box<Apple> {
//                override fun set(t: Apple) {
//                    t.getName()
//                }
//
//                override fun getOut(): Apple {
//                    return Apple()
//                }
//            })
//
//            generic.buyIn(object : Box<Apple>{
//                override fun set(t: Apple) {
//                }
//
//                override fun getOut(): Apple {
//                }
//            })

        }
    }

}